import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

// 按需引入组件
import AutoImport from "unplugin-auto-import/vite";

// 全局注册组件
import Components from "unplugin-vue-components/vite";

// ElementPlus解析器
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// 自动生成路由
import Pages from "vite-plugin-pages";

import Layouts from "vite-plugin-vue-layouts";

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": "/src/",
      path: "path-browserify",
    },
  },
  plugins: [
    vue(),
    Pages({
      dirs: [
        { dir: "src/views", baseRoute: "" },
        // { dir: "src/views/admin/pages", baseRoute: "admin" },
      ],
      exclude: ["**/components/*.vue"],
      extensions: ["vue", "md"],
      importMode(path) {
        return path.includes("about") ? "sync" : "async";
      },
    }),
    Layouts({
      layoutsDirs: "src/layout", // 布局文件存放目录
      defaultLayout: "index", // 默认布局，对应 src/layout/index.vue
    }),
    AutoImport({
      imports: ["vue", "vue-router"],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    createSvgIconsPlugin({
      iconDirs: [resolve(process.cwd(), "src/icons/svg")],
      symbolId: "icon-[dir]-[name]",
    }),
  ],
});
